#include <gnuplotter.h>


/* Keith McLaughln
 * University of South Florida
 * Lawrence Livermore Nat'l Lab
 * 2012 Jun 14
 *
 * I was tired of trying to remember the syntax in gnuplot, and also
 * tired of having to do on-the-fly wacky sorting of 3D data for
 * proper pm3d and wireframe plots (AFAIK there is no way for
 * gnuplot to sort/interpolate your data for you when a grid
 * is required). So yea. This wrapper does exactly that. If you
 * want points or dots, fine, no big deal. This code just imports your 
 * data into gnuplot and either loads your graph interactively, or writes
 * a png to file. If you want a surface(pm3d) or wireframe, this code will
 * sort your data into the expected grid-like pattern, while performing
 * linear interpolation to fill in missing data points (if your grid is
 * irregular, for instance).
 *
 * This source is released under the GNU PUBLIC LICENSE. That means if this
 * code doesn't work as expected and sabotages your million dollar research
 * project, it's not my fault.
 *
 */

void callgnuplot( options_t * options ) {
	char buffer[BUFFSIZE];
	if ( options->interactive ) 
		sprintf(buffer,"gnuplot %s -", options->cmdname );
	else
		sprintf(buffer,"gnuplot %s", options->cmdname);
	system(buffer);
	return;
}
	
int main ( int argc, char ** argv ) {
	options_t * options = calloc(1,sizeof(options_t));

	//command line options
	if ( -1 == parseargs( argc, argv, options )) usage(argv[0],options); //if fail to parse, call usage
	setdefaults(options); //check and set defaults for unset parameters

	//read from stdin into options->readdata
	read(options);

	//if neccessary, define a grid and determine values at each grid point (via kernel average)
//	if ( options->withtype == heat || options->withtype == lines || options->withtype == pm3d ) 
	//	placeongrid(options);

//	makeinputfile(options);
//	callgnuplot(options);
//	cleanup(options);

	printf("geometry %d %d withtype %d\n", 
		options->geometry[0],
		options->geometry[1],
		options->withtype);



	return 0;

}

